
using AutoMapper;
using DTO;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Model;
using Newtonsoft.Json;
using NPOI.SS.Formula.Functions;
using Org.BouncyCastle.Asn1.Crmf;
using SqlSugar;
using System.IdentityModel.Tokens.Jwt;
using System.Net;
using System.Security.Claims;
using System.Security.Cryptography;
using System.Text;
using Util;
using RestSharp;
using Coldairarrow.Util;
using DTO.Output;

namespace API.Controllers
{
    [Route("api/v1/record/[action]")]
    [Authorize]
    public class FaceController : ControllerBase
    {
        protected string CurrentUserId => User.FindFirstValue(JwtRegisteredClaimNames.Jti) ?? "Unknown";

        protected string CurrentUsername => User.FindFirstValue(ClaimTypes.Name) ?? "Unknown";
        Repository<tDoorRecord> _tDoor;
        Repository<tFace> _tFace;
        Repository<tMealReporting> _repMeal;
        Repository<tFoodResidue> _foodResidue;
        Repository<tSignIn> _tSignIn;
        Repository<tAutoMealReporting> _auto;
        Repository<tCanteenMenu> _tCanteenMenu;
        Repository<tPassRule> _tPassRule;
        Repository<tRuleStaff> _tRuleStaff;
        readonly IMapper _mapper;
        ISqlSugarClient _db;
        Repository<tStaff> _staff;

        CancellationToken cancellationToken = new CancellationToken();
        readonly object _lock = new object();
        public FaceController(Repository<tMealReporting> repMeal, Repository<tFoodResidue> foodResidue, Repository<tSignIn> tSignIn, Repository<tCanteenMenu> tCanteenMenu, Repository<tFace> tFace, Repository<tAutoMealReporting> auto, Repository<tDoorRecord> tDoor, Repository<tPassRule> tPassRule, Repository<tRuleStaff> tRuleStaff, IMapper mapper, ISqlSugarClient db, Repository<tStaff> staff)
        {
            _repMeal = repMeal;
            _foodResidue = foodResidue;
            _tSignIn = tSignIn;
            _tCanteenMenu = tCanteenMenu;
            _tFace = tFace;
            _auto = auto;
            _tDoor = tDoor;
            _tPassRule = tPassRule;
            _tRuleStaff = tRuleStaff;
            _mapper = mapper;
            _db = db;
            _staff = staff;
        }
        /// <summary>
        /// 通过UserID获取人脸图片
        /// </summary>
        /// <param name="userId"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ResultMsg<string>> GetUserFace(string userId)
        {
            ResultMsg<string> result = new ResultMsg<string>();
            try
            {
                Util.NLOG.LogHelper.Info("userId:" + userId);
                string userFace = string.Empty;
                var model = await _tFace.GetFirstAsync(x => x.FUserId == userId);
                if (model != null)
                {
                    userFace = model.FPhoto;
                }
                return result.Success(userFace);
            }
            catch (Exception ex)
            {
                Util.NLOG.LogHelper.Error("FaceController-GetUserFace:" + ex);
                return result.Exception();
            }
        }
        /// <summary>
        /// 上传人脸图片
        /// </summary>
        /// <param name="formCollection"></param>
        /// <returns></returns>
        [AllowAnonymous]
        [HttpPost]
        public async Task<ResultMsg<List<string>>> UploadFiles([FromForm] IFormCollection formCollection)
        {
            ResultMsg<List<string>> result = new ResultMsg<List<string>>();
            List<string> list = new List<string>();
            try
            {
                string userid = formCollection["userid"];
                string username = formCollection["username"];
                FormFileCollection fileCollection = (FormFileCollection)formCollection.Files;
                if (fileCollection != null && fileCollection.Count > 0)
                {
                    list = UploadOperate.UploadSteam(fileCollection, "file/face/");
                }
                string thumbnailPath = string.Empty;

                var model = await _tFace.GetFirstAsync(x => x.FUserId == userid && x.FDeleted == false);
                if (model == null)
                {
                    await _tFace.InsertAsync(new tFace
                    {
                        Id=IdHelper.GetId(),
                        FUserId = userid,
                        FDeleted = false,
                        CreatorId = userid,
                        CreateTime = DateTime.Now,
                        FEnter = false,
                        FName = username,
                        FErrMsg = string.Empty,
                        FPhoto = "https://sign.yingdl.com/face/" + list[0],
                        //FThumbnail = thumbnailPath,
                        FDoorEnter = false,
                        FDoorErrMsg = "",
                        FValidCycle = "[]"
                    });
                }
                else
                {
                    var filePath = Path.Combine(Directory.GetCurrentDirectory(), "face", model.FPhoto); //根据你的实际情况来组合文件路径  

                    if (System.IO.File.Exists(filePath))
                    {
                        try
                        {
                            System.IO.File.Delete(filePath);
                        }
                        catch (Exception ex)
                        {
                            Util.NLOG.LogHelper.Error("FaceController-UploadFiles:" + $"删除文件时出错: {ex.Message}");
                        }
                    }
                    model.FEnter = false;
                    model.FPhoto = "https://sign.yingdl.com/face/" + list[0];
                    await _tFace.UpdateAsync(model);
                }
                //往员工表里添加
                if(!await _staff.IsAnyAsync(x=>x.FUserId== userid && !x.FDeleted))
                {
                    tStaff staffModel = new tStaff();
                    staffModel.FUserId= userid;
                    staffModel.FUserName = username;
                    staffModel.FDeleted = false;
                    staffModel.Id=IdHelper.GetId();
                    staffModel.CreateTime = DateTime.Now;
                    staffModel.CreatorId = "";
                    await _staff.InsertAsync(staffModel);
                }
                return result.Success(list);
            }
            catch (Exception ex)
            {
                Util.NLOG.LogHelper.Error("FaceController-UploadFiles:" + ex);
                return result.Exception();
            }
        }

        [HttpPost]
        //更改通行时间
        public async Task<ResultMsg<string>> UpdateTravelTime([FromBody] UpdateTravelTimeInput input)
        {
            ResultMsg<string> result = new ResultMsg<string>();
            try
            {

                var model = await _tFace.GetFirstAsync(x => x.FUserId == input.userId);
                if (model != null)
                {
                    model.FValidCycle = JsonConvert.SerializeObject(input.valid_cycles);
                    await _tFace.UpdateAsync(model);
                }
                else
                {
                    result.Error("找不到该数据!");
                }

                return result.Success();
            }
            catch (Exception ex)
            {
                Util.NLOG.LogHelper.Error("FaceController-DelFace:" + ex);
                return result.Exception();
            }
        }
        [HttpPost]
        //删除人像数据
        public async Task<ResultMsg<string>> UpdateFaceEnter([FromBody] DelFaceInput input)
        {
            ResultMsg<string> result = new ResultMsg<string>();
            try
            {

                var faces = await _tFace.GetListAsync(x => input.FUserId.Contains(x.FUserId));
                foreach (var item in faces)
                {
                    item.FEnter = false;
                    item.FPhoto = "";
                    item.FErrMsg = string.Empty;
                    item.FDoorEnter = false;
                    item.FDoorErrMsg = "";
                }

                await _tFace.UpdateRangeAsync(faces);
                return result.Success();
            }
            catch (Exception ex)
            {
                Util.NLOG.LogHelper.Error("FaceController-DelFace:" + ex);
                return result.Exception();
            }
        }

        [HttpPost]
        //删除人像数据
        public async Task<ResultMsg<string>> DelFace([FromBody] DelFaceInput input)
        {
            ResultMsg<string> result = new ResultMsg<string>();
            try
            {
                var faces = await _tFace.GetListAsync(x => input.FUserId.Contains(x.FUserId));
                foreach (var item in faces)
                {
                    item.FDeleted = true;
                }

                await _tFace.UpdateRangeAsync(faces);
                return result.Success();
            }
            catch (Exception ex)
            {
                Util.NLOG.LogHelper.Error("FaceController-DelFace:" + ex);
                return result.Exception();
            }
        }
        [HttpPost]
        //获取人像列表
        public async Task<ResultMsg<List<FaceOutput>>> GetFaceList([FromBody] FaceListInput input)
        {
            ResultMsg<List<FaceOutput>> result = new ResultMsg<List<FaceOutput>>();
            try
            {
                if (input.PageNum <= 0)
                {
                    return result.Error("PageNum不能小于或等于0");
                }
                if (input.PageSize <= 0)
                {
                    return result.Error("PageSize不能小于或等于0");
                }
                SqlSugar.PageModel pageModel = new SqlSugar.PageModel
                {
                    PageIndex = input.PageNum,
                    PageSize = input.PageSize,
                };
                var exp = Expressionable.Create<tFace>();
                if (!string.IsNullOrWhiteSpace(input.Name))
                {
                    exp.And(x => x.FName.Contains(input.Name));
                }
                exp.And(x => x.FDeleted == false);
                if (input.IsEnter == 1)
                {
                    exp.And(x => x.FEnter == true);
                }
                else if (input.IsEnter == 2)
                {
                    exp.And(x=>x.FEnter==false);
                }
                var list = (await _tFace.GetPageListAsync(exp.ToExpression(), pageModel)).OrderByDescending(x => x.CreateTime).ToList();

                var FoodProcureOutputs = _mapper.Map<List<FaceOutput>>(list);
                string FPassRuleName = "默认";
                foreach (var item in FoodProcureOutputs)
                {
                    var staffModel = _tRuleStaff.GetFirst(c => c.FUserId == item.UserId);
                    if (staffModel != null)
                    {
                        var ruleModel = _tPassRule.GetFirst(c => c.Id == staffModel.FRuleId);
                        if (ruleModel != null)
                        {
                            FPassRuleName = ruleModel.FRuleName;
                        }
                    }
                    item.PassRuleName = FPassRuleName;
                }
                return result.Success(FoodProcureOutputs, pageModel.TotalCount);
            }
            catch (Exception ex)
            {
                Util.NLOG.LogHelper.Error("FaceController-GetFaceList:" + ex);
                return result.Exception();
            }
        }


        [HttpPost]
        [AllowAnonymous]
        public async Task<IActionResult> face([FromBody] FaceRecordInput input)
        {
            //Util.NLOG.LogHelper.Info("input:" + JsonConvert.SerializeObject(input));
            signReturnOutput dao = new signReturnOutput();
            try
            {

                Common commonInstance = new Common(_db); // 使用db实例化Common类
                if (input.sn == "QT75031")
                {
                    tDoorRecord record = new tDoorRecord();
                    foreach (var item in input.logs)
                    {
                        record = new tDoorRecord();
                        record.FUserId = item.user_id;
                        record.FUserName = item.user_name;
                        record.FPassStatus = item.pass_status;
                        record.FRecogType = item.recog_type;
                        record.FRecordTime = Convert.ToDateTime(item.recog_time);
                        record.CreatorId = "Admin";
                        record.CreateTime = DateTime.Now;
                        record.Id = IdHelper.GetId();
                        await _tDoor.InsertAsync(record);
                    }


                    dao.Result = 0;
                    dao.Msg = "";
                    dao.Content = "";
                    return Ok(JsonConvert.SerializeObject(dao));

                }
                else if (input.sn == "H70982")
                {
                    var lunch_start = commonInstance.GetConfig().LunchStartScan;
                    var lunch_end = commonInstance.GetConfig().LunchEndScan;
                    var dinner_start = commonInstance.GetConfig().DinnerStartScan;
                    var dinner_end = commonInstance.GetConfig().DinnerEndScan;
                    DateTime dt = DateTime.Now;
                    DateTime d1 = new DateTime(dt.Year, dt.Month, dt.Day, int.Parse(lunch_start.Split(':')[0]), int.Parse(lunch_start.Split(':')[1]), 0);
                    DateTime d2 = new DateTime(dt.Year, dt.Month, dt.Day, int.Parse(lunch_end.Split(':')[0]), int.Parse(lunch_end.Split(':')[1]), 0);
                    DateTime d3 = new DateTime(dt.Year, dt.Month, dt.Day, int.Parse(dinner_start.Split(':')[0]), int.Parse(dinner_start.Split(':')[1]), 0);
                    DateTime d4 = new DateTime(dt.Year, dt.Month, dt.Day, int.Parse(dinner_end.Split(':')[0]), int.Parse(dinner_end.Split(':')[1]), 0);
                    foreach (var item in input.logs)
                    {
                        dt = DateTime.Parse(item.recog_time);
                        //判断是中午签到还是晚上签到
                        int rType = 0;
                        if (dt >= d1 && dt <= d2)
                        {
                            rType = 1;
                        }
                        else if (dt >= d3 && dt <= d4)
                        {
                            rType = 2;
                        }
                        else
                        {
                            rType = 3;
                        }

                        //找到相关的报餐表ID
                        //id.HasValue有报餐  
                        var model = await _repMeal.GetFirstAsync(x => x.FEID == item.user_id && x.FRTime == dt.Date && x.FDeleted == false && x.FMType == rType);
                        string id = model == null ? "0" : model.Id;
                        tSignIn sign = new tSignIn();
                        if (rType == 1)
                        {
                            sign = await _tSignIn.GetFirstAsync(x => x.FEId == item.user_id && x.CreateTime >= d1 && x.CreateTime <= d2);
                        }
                        else if (rType == 2)
                        {
                            sign = await _tSignIn.GetFirstAsync(x => x.FEId == item.user_id && x.CreateTime >= d3 && x.CreateTime <= d4);
                        }

                        if (sign == null)
                        {
                            await _tSignIn.InsertAsync(new tSignIn
                            {
                                CreatorId = CurrentUserId,
                                CreateTime = dt,
                                FEName = item.user_name,
                                FEEngName = "",
                                FEId = item.user_id,
                                FRId = id,
                                Id = IdHelper.GetId()
                            });
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Util.NLOG.LogHelper.Error("报错:" + ex);
                throw;
            }

            dao.Result = 0;
            dao.Msg = "";
            dao.Content = "";
            return Ok(JsonConvert.SerializeObject(dao));

        }

        [HttpPost]
        [AllowAnonymous]
        public async Task<ResultMsg<object>> GetSign()
        {
            ResultMsg<object> result = new ResultMsg<object>();
            try
            {

                string str = "appid=ct2c8dced2bb630888&limit=2&page=1&access_token=7482691bad5ff0581f05158e3ad75f88";
                string hashString = string.Empty;
                // 创建一个SHA256实例
                SHA256 sha256 = SHA256.Create();

                // 加密输入数据
                byte[] inputBytes = Encoding.UTF8.GetBytes(str);
                byte[] hash = sha256.ComputeHash(inputBytes);
                foreach (byte x in hash)
                {
                    hashString += String.Format("{0:x2}", x);
                }

                var client = new RestClient("https://www.gzchitu.cn/api/openApi/machineList");
                var request = new RestRequest("", RestSharp.Method.Post);
                request.AddParameter("appid", "ct2c8dced2bb630888");
                request.AddParameter("page", "1");
                request.AddParameter("limit", "2");
                request.AddParameter("sign", "fd8756f510f35b8a0893708a294123cee369e2c3715253f5fccd51e5fb44d5da");
                var response = client.Execute(request);

                // 输出加密后的数据
                object ret = null;
                if (response.StatusCode == HttpStatusCode.OK)
                {
                    if (response != null && response.Content != null)
                    {
                        ret = JsonConvert.DeserializeObject(response.Content);
                    }
                }
                else if (response.StatusCode == HttpStatusCode.NotFound)
                {
                    ret = "资源不存在";
                }
                else if (response.StatusCode == HttpStatusCode.BadRequest)
                {
                    ret = "请求不合法";
                }
                return result.Success(ret);
            }
            catch (Exception ex)
            {
                return result.Exception();
            }

        }
        /// <summary>
        /// 获取实时就餐人数
        /// </summary>
        /// <returns></returns>
        [AllowAnonymous]
        [HttpPost]
        public async Task<ResultMsg<GetFoodResidueOutput>> GetFoodResidue()
        {
            ResultMsg<GetFoodResidueOutput> result = new ResultMsg<GetFoodResidueOutput>();
            try
            {
                GetFoodResidueOutput dao = new GetFoodResidueOutput();
                DateTime dt = DateTime.Now;
                int meenType = 0;
                if (dt.Hour >= 8 && dt.Hour <= 14)
                    meenType = 1;
                else if (dt.Hour >= 14 && dt.Hour <= 21)
                {
                    meenType = 2;
                }
                var model = await _tCanteenMenu.GetFirstAsync(x => x.FMTime == DateTime.Now.Date && x.FMType == meenType);
                if (model != null)
                {
                    dao.meen = model.FMName;
                    dao.meen2 = model.FMName2;
                    dao.meen3 = model.FMName3;
                    dao.meen4 = model.FSoup;
                }
                dao.allReport = _repMeal.Count(x => x.FRTime == dt.Date && x.FMType == meenType);
                DateTime start = new DateTime();
                DateTime end = new DateTime();
                if (meenType == 1)
                {
                    start = DateTime.Parse(dt.Date.ToString("yyyy-MM-dd") + " 7:00:00");
                    end = DateTime.Parse(dt.Date.ToString("yyyy-MM-dd") + " 14:00:00");
                }
                else
                {
                    start = DateTime.Parse(dt.Date.ToString("yyyy-MM-dd") + " 14:00:00");
                    end = DateTime.Parse(dt.Date.ToString("yyyy-MM-dd") + " 21:00:00");
                }
                dao.currentEat = await _tSignIn.CountAsync(x => x.CreateTime >= start && x.CreateTime < end);
                var residueModel = await _foodResidue.GetFirstAsync(x => x.CreateTime >= start && x.CreateTime < end);
                var odd = residueModel == null ? 0 : residueModel.FRealresidue;
                dao.residue = dao.allReport - dao.currentEat + odd;

                return result.Success(dao);
            }
            catch (Exception ex)
            {
                Util.NLOG.LogHelper.Error("tFoodResidueController-GetFoodResidue:" + ex);
                return result.Exception();
            }
        }
        /// <summary>
        /// 发布剩余份量
        /// </summary>
        /// <returns></returns>
        [AllowAnonymous]
        [HttpPost]
        public async Task<ResultMsg<object>> ReleaseFoodResidue(ReleaseFoodResidueInput input)
        {
            ResultMsg<object> result = new ResultMsg<object>();
            try
            {
                //数据库进行存在更改，没有插入操作
                DateTime dt = DateTime.Now;
                tFoodResidue model = new tFoodResidue();
                if (dt.Hour >= 8 && dt.Hour <= 14)
                {
                    model = await _foodResidue.GetFirstAsync(x => x.CreateTime >= DateTime.Parse(dt.Date.ToString("yyyy-MM-dd") + " 7:00:00") && x.CreateTime < DateTime.Parse(dt.Date + " 14:00:00"));
                }
                else if (dt.Hour >= 14 && dt.Hour <= 21)
                {
                    model = await _foodResidue.GetFirstAsync(x => x.CreateTime >= DateTime.Parse(dt.Date.ToString("yyyy-MM-dd") + " 14:00:00") && x.CreateTime <= DateTime.Parse(dt.Date + " 21:00:00"));
                }

                if (model == null)
                {
                    await _foodResidue.InsertAsync(new tFoodResidue
                    {
                        Id=IdHelper.GetId(),
                        FResidue = input.Count,
                        FRealresidue = input.Count,
                        CreatorId = "Admin",
                        CreateTime = DateTime.Now,
                    });
                }
                //往小程序发布模版信息

                var client = new RestClient("https://app.yingdl.com:9527/Wechat/SendMsgToAllUser");
                var request = new RestRequest("", RestSharp.Method.Get);
                request.AddParameter("userName", "饭堂阿姨");
                request.AddParameter("content", string.Format("晚餐剩余{0}份,快来吃饭呀", input.Count));
                request.AddParameter("first", "");
                request.AddParameter("remark", "");
                request.AddParameter("path", "pages/cantmeen/odd");
                var response = client.Execute(request);

                object ret = null;
                if (response.StatusCode == HttpStatusCode.OK)
                {
                    if (response != null && response.Content != null)
                    {
                        ret = JsonConvert.DeserializeObject(response.Content);
                    }
                }
                else if (response.StatusCode == HttpStatusCode.NotFound)
                {
                    ret = "资源不存在";
                }
                else if (response.StatusCode == HttpStatusCode.BadRequest)
                {
                    ret = "请求不合法";
                }
                return result.Success(ret);
            }
            catch (Exception ex)
            {
                Util.NLOG.LogHelper.Error("tFoodResidueController-ReleaseFoodResidue:" + ex);
                return result.Exception();
            }
        }

        /// <summary>
        /// 报余餐
        /// </summary>
        /// <returns></returns>
        [AllowAnonymous]
        [HttpPost]
        public async Task<ResultMsg<string>> ReportFoodResidue(ReportFoodResidueInput input)
        {
            ResultMsg<string> result = new ResultMsg<string>();
            try
            {
                DateTime dt = DateTime.Now;
                DateTime start = new DateTime();
                DateTime end = new DateTime();
                int mType = 0;
                if (dt.Hour >= 8 && dt.Hour <= 14)
                {
                    mType = 1;
                    start = DateTime.Parse(dt.Date.ToString("yyyy-MM-dd") + " 7:00:00");
                    end = DateTime.Parse(dt.Date.ToString("yyyy-MM-dd") + " 14:00:00");
                }
                else if (dt.Hour >= 14 && dt.Hour <= 21)
                {
                    mType = 2;
                    start = DateTime.Parse(dt.Date.ToString("yyyy-MM-dd") + " 14:00:00");
                    end = DateTime.Parse(dt.Date.ToString("yyyy-MM-dd") + " 21:00:00");
                }
                var model = await _foodResidue.GetSingleAsync(x => x.CreateTime >= start && x.CreateTime < end);
                lock (_lock)
                {
                    if (model.FRealresidue <= 0)
                    {
                        return result.Success("不好意思哦，已经没有餐了");
                    }
                    else
                    {
                        model.FRealresidue--;
                        _foodResidue.Update(model);

                        //报餐表插入数据,防止重复点餐,通过菜单ID为空来判断是否点过
                        _repMeal.Insert(new tMealReporting
                        {
                            FMType = mType,
                            FEID = input.userId,
                            FEName = input.userName,
                            FRTime = DateTime.Now.Date,
                            FDeptName = "",
                            FDeleted = false,
                            FWorkOver = false,
                            FCancellation = false,
                            FCancelReason = string.Empty,
                            FCancelTime = DateTime.MinValue,
                            CreatorId = CurrentUserId,
                        });
                        return result.Success("成功报餐!");
                    }
                }

            }
            catch (Exception ex)
            {
                Util.NLOG.LogHelper.Error("tFoodResidueController-ReleaseFoodResidue:" + ex);
                return result.Exception();
            }
        }
        /// <summary>
        /// 小程序端获取报余餐相关信息
        /// </summary>
        /// <returns></returns>
        [AllowAnonymous]
        [HttpPost]
        public async Task<ResultMsg<GetFoodResidueOutput>> GetFoodResidueByMini(FoodResidueByMiniInput input)
        {
            ResultMsg<GetFoodResidueOutput> result = new ResultMsg<GetFoodResidueOutput>();
            try
            {
                GetFoodResidueOutput dao = new GetFoodResidueOutput();
                DateTime dt = DateTime.Now;
                int meenType = 0;
                if (dt.Hour >= 8 && dt.Hour <= 14)
                    meenType = 1;
                else if (dt.Hour >= 14 && dt.Hour <= 21)
                {
                    meenType = 2;
                }
                var model = await _tCanteenMenu.GetFirstAsync(x => x.FMTime == DateTime.Now.Date && x.FMType == meenType);
                if (model != null)
                {
                    dao.meen = model.FMName;
                    dao.meen2 = model.FMName2;
                    dao.meen3 = model.FMName3;
                    dao.meen4 = model.FSoup;
                }
                dao.allReport = await _repMeal.CountAsync(x => x.FRTime == dt.Date && x.FMType == meenType);
                DateTime start = new DateTime();
                DateTime end = new DateTime();
                if (meenType == 1)
                {
                    start = DateTime.Parse(dt.Date.ToString("yyyy-MM-dd") + " 7:00:00");
                    end = DateTime.Parse(dt.Date.ToString("yyyy-MM-dd") + " 14:00:00");
                }
                else
                {
                    start = DateTime.Parse(dt.Date.ToString("yyyy-MM-dd") + " 14:00:00");
                    end = DateTime.Parse(dt.Date.ToString("yyyy-MM-dd") + " 21:00:00");
                }
                dao.currentEat = await _tSignIn.CountAsync(x => x.CreateTime >= start && x.CreateTime < end);
                var odd = (await _foodResidue.GetFirstAsync(x => x.CreateTime >= start && x.CreateTime < end)).FRealresidue;
                dao.residue = dao.allReport - dao.currentEat + odd;
                dao.Report = await _repMeal.CountAsync(x => x.FEID == input.userId && x.FEName == input.userName && x.FMType == meenType && x.FRTime == DateTime.Now.Date) > 0 ? true : false;

                return result.Success(dao);
            }
            catch (Exception ex)
            {
                Util.NLOG.LogHelper.Error("tFoodResidueController-GetFoodResidue:" + ex);
                return result.Exception();
            }
        }
        /// <summary>
        /// 二维码在线对比
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost("qrcode_recognition")]
        [AllowAnonymous]
        public IActionResult qrcode_recognition([FromBody] recognitionQrCodeInput input)
        {
            Util.NLOG.LogHelper.Info(JsonConvert.SerializeObject(input));
            recognitionQrCodeOutput dao = new recognitionQrCodeOutput();
            try
            {

                dao.Result = 0;
                dao.Msg = "";
                dao.Content = new ContentOutput();
            }
            catch (Exception ex)
            {
                Util.NLOG.LogHelper.Error(ex.ToString());
            }
            return Ok(JsonConvert.SerializeObject(dao));

        }
    }
}
